bitkeeper revision 1.1159.269.7 (4239b07dqrgbq5nyeaRv54s7lw6AsA)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Thu, 17 Mar 2005 16:29:49 +0000 (16:29 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Thu, 17 Mar 2005 16:29:49 +0000 (16:29 +0000)
Add sxpr function for installing a new type.

Signed-off-by: Mike Wray <mike.wray@hp.com>
tools/libxutil/sxpr.c
tools/libxutil/sxpr.h

index 5a9364a317d648abeb0fa0ea82f004f849875237..02a5040b52aa117f2f162ecb5a2678734eba7436 100644 (file)
@@ -82,6 +82,30 @@ static SxprType types[1024] = {
 /** Number of entries in the types array. */
 static int type_sup = sizeof(types)/sizeof(types[0]);
 
+/** Define a type.
+ * The tydef must have a non-zero type code.
+ * It is an error if the type code is out of range or already defined.
+ *
+ * @param tydef type definition
+ * @return 0 on success, error code otherwise
+ */
+int def_sxpr_type(SxprType *tydef){
+    int err = 0;
+    int ty = tydef->type;
+    if(ty < 0 || ty >= type_sup){
+        err = -EINVAL;
+        goto exit;
+    }
+    if(types[ty].type){
+        err = -EEXIST;
+        goto exit;
+    }
+    types[ty] = *tydef;
+  exit:
+    return err;
+    
+}
+
 /** Get the type definition for a given type code.
  *
  * @param ty type code
index 8b01e84736e5d79f293574ba1ec92dc4e5f926b8..761b8b2da711dcda07acc5a53b4a9fd1afe1d100 100644 (file)
@@ -307,6 +307,7 @@ typedef struct SxprType {
 } SxprType;
 
 
+extern int def_sxpr_type(SxprType *tydef);
 extern SxprType *get_sxpr_type(int ty);
 
 /** Free the pointer in an sxpr.